| Conditions | 1 |
| Paths | 1 |
| Total Lines | 90 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var WPInv_Admin; |
||
| 3 | jQuery( document ).ready( function ( $ ) { |
||
| 4 | |||
| 5 | var WPInv_Recurring = { |
||
| 6 | init: function () { |
||
| 7 | |||
| 8 | //Recurring select field conditionals |
||
| 9 | this.edit_product_id(); |
||
| 10 | this.edit_profile_id(); |
||
| 11 | this.edit_txn_id(); |
||
| 12 | this.delete(); |
||
| 13 | |||
| 14 | }, |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Edit Subscription Text Input |
||
| 18 | */ |
||
| 19 | edit_subscription_input: function (link, input) { |
||
| 20 | |||
| 21 | //User clicks edit |
||
| 22 | if (link.text() === WPInv_Admin.action_edit) { |
||
|
|
|||
| 23 | //Preserve current value |
||
| 24 | link.data('current-value', input.val()); |
||
| 25 | //Update text to 'cancel' |
||
| 26 | link.text(WPInv_Admin.action_cancel); |
||
| 27 | } else { |
||
| 28 | //User clicked cancel, return previous value |
||
| 29 | input.val(link.data('current-value')); |
||
| 30 | //Update link text back to 'edit' |
||
| 31 | link.text(WPInv_Admin.action_edit); |
||
| 32 | } |
||
| 33 | |||
| 34 | }, |
||
| 35 | |||
| 36 | edit_profile_id: function() { |
||
| 37 | |||
| 38 | $('.wpinv-edit-sub-profile-id').on('click', function(e) { |
||
| 39 | e.preventDefault(); |
||
| 40 | |||
| 41 | var link = $(this); |
||
| 42 | var profile_input = $('input.wpinv-sub-profile-id'); |
||
| 43 | WPInv_Recurring.edit_subscription_input(link, profile_input); |
||
| 44 | |||
| 45 | $('.wpinv-sub-profile-id').toggle(); |
||
| 46 | $('#wpinv-sub-profile-id-update-notice').slideToggle(); |
||
| 47 | }); |
||
| 48 | |||
| 49 | }, |
||
| 50 | |||
| 51 | edit_product_id: function() { |
||
| 52 | |||
| 53 | $('.wpinv-sub-product-id').on('change', function(e) { |
||
| 54 | e.preventDefault(); |
||
| 55 | |||
| 56 | $('#wpinv-sub-product-update-notice').slideDown(); |
||
| 57 | }); |
||
| 58 | |||
| 59 | }, |
||
| 60 | |||
| 61 | edit_txn_id: function() { |
||
| 62 | |||
| 63 | $('.wpinv-edit-sub-transaction-id').on('click', function(e) { |
||
| 64 | e.preventDefault(); |
||
| 65 | |||
| 66 | var link = $(this); |
||
| 67 | var txn_input = $('input.wpinv-sub-transaction-id'); |
||
| 68 | WPInv_Recurring.edit_subscription_input(link, txn_input); |
||
| 69 | |||
| 70 | $('.wpinv-sub-transaction-id').toggle(); |
||
| 71 | }); |
||
| 72 | |||
| 73 | }, |
||
| 74 | |||
| 75 | delete: function() { |
||
| 76 | |||
| 77 | $('.wpinv-delete-subscription').on('click', function(e) { |
||
| 78 | |||
| 79 | if( confirm( WPInv_Admin.delete_subscription ) ) { |
||
| 80 | return true; |
||
| 81 | } |
||
| 82 | |||
| 83 | return false; |
||
| 84 | }); |
||
| 85 | |||
| 86 | } |
||
| 87 | |||
| 88 | }; |
||
| 89 | |||
| 90 | WPInv_Recurring.init(); |
||
| 91 | |||
| 92 | } ); |
||
| 93 |